<style>
a {
	color:#000000;
    font-size:12px;
	text-decoration: none;
}
</style>
<script type="text/javascript">

	$(function() {
		$('#resource_sub_treegrid_${jsid?default('')}').treegrid({
			url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-datagrid.json?key=${key?default('')}',
			queryParams:{id:'${parent.id?default('')}'},
			idField : 'id',
			treeField : 'text',
			parentField : 'pId',
			fit : true,
			nowrap:false,
			fitColumns : true,
			border : false,
			frozenColumns : [ [{
				title : 'bianhao',
				field : 'id',
				width : 150,
				hidden : true
			},{
				field : 'text',
				title : '${action.getDatagridTitle('name')}',
				width : 200
			} ] ],
			columns : [ [{
				field : 'keyValue',
				title : '${action.getDatagridTitle('keyValue')}',
				width : 120,
				formatter : function(value, row, index) {
					return row.attributes.keyValue;
				}
			},{
				field : 'comments',
				title : '${action.getDatagridTitle('comments')}',
				width : 150,
				formatter : function(value, row, index) {
					return row.attributes.comments;
				}
			}, {
				field : 'PId',
				title : '上级菜单ID',
				width : 150,
				hidden : true
			},{
				field : 'action',
				title : '${action.getProperty('net.esj.background.message','bg.datagrid.action')}',
				width : 50,
				formatter : function(value, row, index) {
					var reval = '';
					if(row.attributes.keyType=='${type?default('')}'){
						reval +='<a onclick="resource_sub_edit_${jsid?default('')}(\''+row.id+'\',\''+row.PId+'\');" href="javascript:;; ">${action.getProperty('net.esj.background.message','bg.datagrid.edit')}</a>&nbsp;';
						reval +='<a onclick="resource_sub_delete_${jsid?default('')}(\''+row.id+'\');" href="javascript:;;" >${action.getProperty('net.esj.background.message','bg.datagrid.delete')}</a>';
					}
					else if(row.attributes.hasLeaf){
						reval +='&nbsp;<a onclick="resource_sub_add_child_${jsid?default('')}(\''+row.id+'\');" href="javascript:;;" >添加下级</a>';
					}
					return reval;
				}
			} ] ]
			<#if add>
			,
			toolbar : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-add',
				handler : function() {
					resource_sub_add_${jsid?default('')}();
				}
			}]
			</#if>
		});

	});

	function resource_sub_add_${jsid?default('')}() {
		$('<div/>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-form.htm?parent.id=${parent.id?default('')}&key=${key?default('')}&type=${type?default('')}&jsid=${jsid?default('')}&cascade=${cascade?string('true','false')}&n='+Math.random(),
			width : 600,
			height : 400,
			modal : true,
			title : '${action.getText('form.add.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resource_sub_form_${jsid?default('')}').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-add.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							if(json.level!='error'){
								$.messager.alert(json.title,json.msg,json.level);
								d.dialog('destroy');
								$.post('${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-datagrid.json',{key:'${key?default('')}',id:'${parent.id?default('')}'},function(data){
									$("#resource_sub_treegrid_${jsid?default('')}").treegrid('loadData',data);
								},'JSON');

							}else{
								$.messager.alert(json.title,json.msg,json.level);
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
	function resource_sub_edit_${jsid?default('')}(id,pId) {
		$('<div>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-form.htm?parent.id=${parent.id?default('')}&key=${key?default('')}&jsid=${jsid?default('')}&cascade=${cascade?string('true','false')}&n='+Math.random(),
			width : 600,
			height : 400,
			modal : true,
			title : '${action.getText('form.edit.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.edit')}',
				iconCls : 'icon-edit',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resource_sub_form_${jsid?default('')}').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-update.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							$.messager.alert(json.title,json.msg,json.level);
							d.dialog('destroy');
							$.post('${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-datagrid.json',{key:'${key?default('')}',id:'${parent.id?default('')}'},function(data){
								$("#resource_sub_treegrid_${jsid?default('')}").treegrid('loadData',data);
							},'JSON');
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			},
			onLoad : function() {
				$('#resource_sub_form_${jsid?default('')}').form('load', '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-load.json?id='+id+'&key=${key?default('')}&n='+Math.random());
			}
		});
	}
	
	function resource_sub_delete_${jsid?default('')}(id) {
		if (id != undefined) {
			$('#resource_sub_treegrid_${jsid?default('')}').treegrid('select', id);
		}
		var node = $('#resource_sub_treegrid_${jsid?default('')}').treegrid('getSelected');
		if (node) {
			$.messager.confirm('${action.getProperty('net.esj.background.message','bg.message.info')}', '${action.getText('list.grid.delete.ask')}', function(b) {
				if (b) {
					$.ajax({
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-delete.json',
						data : {
							deletes : node.id,
							key:'${key?default('')}'
						},
						dataType : 'JSON',
						success : function(json) {
							$.messager.alert(json.title,json.msg,json.level);
							$.post('${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-datagrid.json',{key:'${key?default('')}',id:'${parent.id?default('')}'},function(data){
								$("#resource_sub_treegrid_${jsid?default('')}").treegrid('loadData',data);
							},'JSON');
						}
					});
				}
			});
		}
	}

	function resource_sub_add_child_${jsid?default('')}(id){
		$('<div/>').dialog({
			href : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-form.htm?parent.id='+id+'&key=${key?default('')}&type=${type?default('')}&jsid=${jsid?default('')}&cascade=${cascade?string('true','false')}&n='+Math.random(),
			width : 600,
			height : 400,
			modal : true,
			title : '${action.getText('form.add.title')}',
			buttons : [ {
				text : '${action.getProperty('net.esj.background.message','bg.datagrid.add')}',
				iconCls : 'icon-add',
				handler : function() {
					var d = $(this).closest('.window-body');
					$('#resource_sub_form_${jsid?default('')}').form('submit', {
						url : '${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-add.json',
						onSubmit: function(){
							return $(this).form('validate');
        				},
						success : function(json) {
							eval("json="+json);
							if(json.level!='error'){
								$.messager.alert(json.title,json.msg,json.level);
								d.dialog('destroy');
								$.post('${request.contextPath}${namespace?default('')}/mp/sysres/resource_sub-datagrid.json',{key:'${key?default('')}',id:'${parent.id?default('')}'},function(data){
									$("#resource_sub_treegrid_${jsid?default('')}").treegrid('loadData',data);
								},'JSON');

							}else{
								$.messager.alert(json.title,json.msg,json.level);
							}
						}
					});
				}
			} ],
			onClose : function() {
				$(this).dialog('destroy');
			}
		});
	}
</script>
<table id="resource_sub_treegrid_${jsid?default('')}"></table>
<!--div id="admin_cdgl_menu" class="easyui-menu" style="width:120px;display: none;">
	<div onclick="admin_cdgl_appendFun();" data-options="iconCls:'icon-add'">增加</div>
	<div onclick="admin_cdgl_deleteFun();" data-options="iconCls:'icon-remove'">删除</div>
	<div onclick="admin_cdgl_editFun();" data-options="iconCls:'icon-edit'">编辑</div>
</div-->